package program.Command;

import program.Atom;
import program.SExprList;
import program.SExpression;
import roborally.Robot;
import Exceptions.ElementPlacementError;
import Exceptions.IllegalCoordinateException;
import Exceptions.PickupError;
import Exceptions.ShootException;
import Exceptions.TerminationError;

/**
 * A class representing a command.
 * 
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */

public abstract class Command {
	
	/**
	 * This method executes one step.
	 * @param 	robot
	 * 			The robot who will execute the command.
	 * @throws 	IllegalCoordinateException
	 * @throws 	TerminationError
	 * @throws 	ShootException
	 * @throws 	PickupError
	 * @throws 	ElementPlacementError
	 */
	public abstract Command execute(Robot robot)
			throws IllegalCoordinateException, TerminationError,
			ShootException, PickupError, ElementPlacementError;

	public abstract SExpression toSExpression();

	/**
	 * This method returns a SExprList-object which contains an ArrayList where the given atom is added to.
	 * @param 	atom
	 * 			The string representation of the atom that will be added to the arraylist of the sexpr-object.
	 * @return	Returns a SExprList-object
	 */
	protected SExpression makeSingletonSExpressionList(String atom) {
		SExprList sexpr = new SExprList();
		sexpr.add(new Atom(atom)); 	
		return sexpr;
	}
	
	/**
	 * This method returns a string representation of the SExpressions.
	 */
	public String toString() {
		return this.toSExpression().toString();
	}
}
